
import {reqSearchInfo} from "@/api";
const state= {
    searchInfo:{}
}
const mutations = {
    RECEIVE_SEARCHINFO(state,searchInfo){
        state.searchInfo = searchInfo;
    }
}

const actions = {
    async getSearchInfoHandler ({commit},searchParams){
        try {
            const res = await reqSearchInfo(searchParams);
            if (res && res.code === 200){
                commit('RECEIVE_SEARCHINFO',res.data);
                // console.log(res.data)
            }
            
        }catch (error){
            alert("获取搜索页数据失败")
        }
    }
}

const getters = {
    attrsList(state){
        return state.searchInfo.attrsList || [];
    },
    goodsList(state){
        return state.searchInfo.goodsList || [];
    },
    trademarkList(state){
        return state.searchInfo.trademarkList || [];
    },
    total(state){
        return state.searchInfo.total || []
    }
}

export default {
    //开启命名空间
    namespaced: true,
    state,
    mutations,
    actions,
    getters
}